import axios from 'axios'

import { Notify, Toast } from 'vant';
var toast = null;
const request = axios.create({
    baseURL: '/',
    timeout: 5000,
    headers: {
        post: {
            "Content-Type": "application/x-www-form-urlencoded",
            // "Content-Type": "application/json"
        }
    }
})

request.interceptors.request.use(
    function (config) {
        if (config.loading) {
            toast = Toast.loading({
                ...config.loading
            })
        }
        return config;
    }, function (err) {
        Promise.reject(err)
    }
)
request.interceptors.response.use(
    function (data) {
        if (toast != null) toast.clear();
        return data;
    },
    function (err) {
        if (toast != null) toast.clear();

        Notify({
            type: 'danger',
            message: err.message
        })
        Promise.reject(err)
    }
)

export default request